package com.hdax.dmw.user.api;

import cn.hutool.crypto.digest.DigestUtil;
import com.hdax.dmw.common.utils.Result;
import com.hdax.dmw.user.dtos.LoginDto;
import com.hdax.dmw.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class LoginApi {

    @Autowired
    private UserService userService;

    @PostMapping(path = "/user/login")
    public Result<LoginDto> login(@RequestBody Map<String,String> params){
        //获取请求参数
        String phone = params.get("phone");
        String password = DigestUtil.md5Hex(params.get("password"));
        return userService.login(phone, password);
    }
}
